VERSION 5.00 Begin VB.Form frmSineWave BorderStyle = 1 'Fixed Single Caption = "Form1" ClientHeight = 5265 ClientLeft = 105 ClientTop = 675 ClientWidth = 8865 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False Moveable = 0 'False ScaleHeight = 351 ScaleMode = 3 'Pixel ScaleWidth = 591 StartUpPosition = 2 'CenterScreen Begin VB.TextBox txXUnit BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 7875 MaxLength = 4 TabIndex = 15 Text = "35" Top = 4875 Width = 900 End Begin VB.TextBox txXMult BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 5700 MaxLength = 4 TabIndex = 7 Text = "1" Top = 4500 Width = 900 End Begin VB.CommandButton cmdGo Caption = "&Go" Default = -1 'True BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 7875 TabIndex = 6 Top = 4500 Width = 915 End Begin VB.PictureBox pctGraph AutoRedraw = -1 'True BackColor = &H00C0C0C0& ClipControls = 0 'False Height = 3990 Left = 75 ScaleHeight = 262 ScaleMode = 3 'Pixel ScaleWidth = 577 TabIndex = 0 Top = 75 Width = 8715 End Begin VB.TextBox txWide BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 3525 MaxLength = 4 TabIndex = 4 Text = "1" Top = 4500 Width = 900 End Begin VB.ComboBox cbWaveName BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 ItemData = "SineWave.frx":0000 Left = 5700 List = "SineWave.frx":0016 TabIndex = 3 Text = "SIN" Top = 4875 Width = 900 End Begin VB.TextBox txHigh BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 3525 MaxLength = 4 TabIndex = 2 Text = "1" Top = 4875 Width = 900 End Begin VB.TextBox txYPos BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 1350 MaxLength = 4 TabIndex = 1 Text = "0" Top = 4875 Width = 900 End Begin VB.TextBox txXPos BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 1350 MaxLength = 4 TabIndex = 5 Text = "0" Top = 4500 Width = 900 End Begin VB.Label Label7 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "X Unit (pixels):" Height = 195 Left = 6825 TabIndex = 16 Top = 4875 Width = 1005 End Begin VB.Label lblScale AutoSize = -1 'True BackStyle = 0 'Transparent Height = 195 Left = 75 TabIndex = 14 Top = 4125 Width = 45 End Begin VB.Label Label6 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Wave Type:" Height = 195 Left = 4770 TabIndex = 13 Top = 4875 Width = 885 End Begin VB.Label Label5 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Width Multiplier:" Height = 195 Left = 4530 TabIndex = 12 Top = 4500 Width = 1125 End Begin VB.Label Label4 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "X Axis Position:" Height = 195 Left = 225 TabIndex = 11 Top = 4500 Width = 1080 End Begin VB.Label Label3 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Wavelength:" Height = 195 Left = 2565 TabIndex = 10 Top = 4500 Width = 915 End Begin VB.Label Label2 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Amplitude:" Height = 195 Left = 2745 TabIndex = 9 Top = 4875 Width = 735 End Begin VB.Label Label1 Alignment = 1 'Right Justify AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Y Axis Position:" Height = 195 Left = 225 TabIndex = 8 Top = 4875 Width = 1080 End Attribute VB_Name = "frmSineWave" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Sub Graph() Dim i As OrderedPair Dim Pt1 As OrderedPair, Pt2 As OrderedPair Dim Began As Boolean, NextSwp As Boolean Dim Start As OrderedPair On Error GoTo Infinite pctGraph.DrawWidth = 1 pctGraph.ForeColor = vbGreen Start.X = CInt(-CenterPoint.X * 180 / PixelUnit) Start.Y = CInt((pctGraph.ScaleWidth - CenterPoint.X) * 180 / PixelUnit) For i.X = Start.X To Start.Y If NextSwp = True Then NextSwp = False Began = False End If i.Y = GetWaveY(i.X) Pt1.X = 2 * WvWide * (WvXMult * i.X + WvXPos) * PixelUnit / 180 Pt1.Y = i.Y + (-WvYPos * PixelUnit) Pt1 = GetGraphPos(Pt1) If Abs(Wave(i.X)) > ScaleHeight Then If NextSwp = False Then Pt1.Y = ScaleHeight * GetSign(Pt1.Y) End If NextSwp = True End If If Began Then pctGraph.Line (Pt1.X, Pt1.Y)-(Pt2.X, Pt2.Y) End If If Not Began Then Began = True Pt2 = Pt1 Next i.X Exit Sub Infinite: NextSwp = True Resume Next End Sub Sub DrawGraph() Dim Location As OrderedPair, i As Integer Dim CX As Currency, CY As Currency pctGraph.Cls pctGraph.ForeColor = vbBlack If PixelUnit = 0 Then PixelUnit = 35 CX = CenterPoint.X / PixelUnit CY = CenterPoint.Y / PixelUnit Squares.X = Int(pctGraph.ScaleWidth / PixelUnit) + 1 + 1 * Abs(Int(GetFraction(CenterPoint.X / PixelUnit) > 0)) Squares.Y = Int(pctGraph.ScaleWidth / PixelUnit) + 1 + 1 * Abs(Int(GetFraction(CenterPoint.Y / PixelUnit) > 0)) Debug.Print Squares.X Location.X = GetFraction(CX) * PixelUnit Location.Y = GetFraction(CY) * PixelUnit DrawLines Location, True DrawLines Location, False DrawAxis DisplayInf End Sub Private Sub DrawLines(Beginning As OrderedPair, XMode As Boolean) Dim i As Long, POS As Currency Dim Finished As Boolean i = -1 DrawWidth = 1 ForeColor = vbBlack Do Until Finished = True i = i + 1 If XMode Then POS = Beginning.X + (i * PixelUnit) pctGraph.Line (POS, 0)-(POS, pctGraph.ScaleHeight) Finished = (i > pctGraph.ScaleWidth) Else POS = Beginning.Y + (i * PixelUnit) pctGraph.Line (0, POS)-(pctGraph.ScaleWidth, POS) Finished = (i > pctGraph.ScaleWidth) End If Loop End Sub Sub DrawAxis() pctGraph.DrawWidth = 1 pctGraph.ForeColor = vbMagenta pctGraph.Line (0, CenterPoint.Y)-(pctGraph.ScaleWidth, CenterPoint.Y) pctGraph.ForeColor = vbCyan pctGraph.Line (CenterPoint.X, 0)-(CenterPoint.X, pctGraph.ScaleHeight) End Sub Private Sub cmdGo_Click() WvType = GetType(cbWaveName.Text) WvHigh = Val(txHigh) WvWide = Val(txWide) WvXPos = Val(txXPos) WvYPos = Val(txYPos) WvXMult = Val(txXMult) PixelUnit = Val(txXUnit) DrawGraph Graph DisplayInf End Sub Sub DisplayInf() Caption = "y = " & WvYPos & " + " & WvHigh & " " & WaveName & " " & WvXMult & " [ (" & WvWide & ") X + " & WvXPos & " ]" lblScale = "(Box Scale = 90 x 1)" End Sub Private Sub pctGraph_DblClick() WvWide = -0.25 WvHigh = -1 WvXPos = 2 WvYPos = -5 WvType = Int(Rnd * 3) CenterPoint.X = pctGraph.ScaleWidth / 2 CenterPoint.Y = pctGraph.ScaleHeight / 2 PixelUnit = 25 DrawGraph Graph End Sub Function GetFraction(Number As Currency) As Currency GetFraction = Number - Int(Number) End Function Function GetInteger(Number As Currency) As Integer GetInteger = Number - (Number - (Int(Number))) End Function Private Sub pctGraph_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button <> 2 Then Exit Sub CenterPoint.X = X CenterPoint.Y = Y DrawGraph Graph End Sub Sub FitText(Ctl As Control) Dim Blink As Integer Blink = Ctl.SelStart Ctl.SelText = "" Ctl.SelStart = 0 PositionLabels Ctl.SelStart = Blink End Sub